﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DAL_Class
/// </summary>
public class DAL_Class : clsConnection
{
    DataTable dt = new DataTable();
    clsQueryList clsquery = new clsQueryList();
    
    public DataTable DAL_Class_getAllData()
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM Class order by classid");
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_Class_addtodel(int id)
    {
        try
        {
            string sql = "delete from Class where id=" + id;
            clsquery.addSQL(sql);
        }
        catch
        {
            return false;
        }
        return true;
    }

    public Boolean DAL_Class_del()
    {
        try
        {
            clsquery.Execute();
        }
        catch
        {
            return false;
        }
        return true;
    }
    public DataTable DAL_Class_getMaxId()
    {
        try
        {
            dt = ExcuteQuery("SELECT max(id) as id FROM Class");
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_Class_getAllById(int id)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM Class WHERE id=" + id);
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_Class_getAllByClassid(string cid)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM Class WHERE classid='" + cid + "'");
        }
        catch
        {
        }
        return dt;
    }
    //moi them vao
    public DataTable DAL_Class_getData()
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM Class where status = 1");
        }
        catch
        {
        }
        return dt;
    }
    public DataTable DAL_Class_getSearch(string username, string name)
    {
        try
        {
            dt = ExcuteQuery("SELECT * FROM Class WHERE classid Like '%" + username + "%' AND Name LIKE N'%" + name + "%'");
        }
        catch
        {
        }
        return dt;
    }
    public Boolean DAL_Class_Update(DTO_Class obj)
    {
        try
        {
            string sql = "UPDATE Class SET name = @name, classtype = @classtype, classid = @classid, amout = 40, Status = @status WHERE classid = @classid";
            AddParameter(new SqlParameter("@name", obj.Name));
            AddParameter(new SqlParameter("@classtype", obj.Classtype));
            AddParameter(new SqlParameter("@classid", obj.Classid));
            //AddParameter(new SqlParameter("@province_id", obj.Province_Id));
            //AddParameter(new SqlParameter("@address", obj.Address));
            //AddParameter(new SqlParameter("@email", obj.Email));
            //AddParameter(new SqlParameter("@tel", obj.Tel));
            AddParameter(new SqlParameter("@status", obj.Status));

            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch
        {
            return false;
        }
    }
    public Boolean DAL_Class_Insert(DTO_Class obj)
    {
        try
        {
            string sql = "INSERT INTO Class(classid, name, amout, classtype, status) VALUES(@classid, @name, 40, @classtype, @status)";
            AddParameter(new SqlParameter("@name", obj.Name));
            AddParameter(new SqlParameter("@classtype", obj.Classtype));
            AddParameter(new SqlParameter("@classid", obj.Classid));
            //AddParameter(new SqlParameter("@province_id", obj.Province_Id));
            //AddParameter(new SqlParameter("@address", obj.Address));
            //AddParameter(new SqlParameter("@email", obj.Email));
            //AddParameter(new SqlParameter("@tel", obj.Tel));
            AddParameter(new SqlParameter("@status", obj.Status));

            if (ExcuteNonQuery(sql))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        catch
        {
            return false;
        }
    }
}